package cn.ac.iie.di.ban.ycl.cleaner;

import cn.ac.iie.di.datadock.rdata.exchange.client.core.REFieldType;
import cn.ac.iie.di.datadock.rdata.exchange.client.exception.REConnectionException;
import cn.ac.iie.di.datadock.rdata.exchange.client.exception.RESessionException;
import cn.ac.iie.di.datadock.rdata.exchange.client.v1.connection.REConnection;
import cn.ac.iie.di.datadock.rdata.exchange.client.v1.session.RESendSession;
import cn.ac.iie.di.datadock.rdata.exchange.client.v1.session.RESendSessionBuilder;
import java.util.HashMap;

/**
 *
 * @author zwlin
 */
public class MQSender {

    public static void main(String[] args) throws RESessionException, REConnectionException {

        REConnection conn = new REConnection("192.168.11.94:9879");
//            REConnection conn = new REConnection("192.168.4.43:9876");

        //builder
        RESendSessionBuilder builder = (RESendSessionBuilder) conn.getSendSessionBuilder("twb_msg_0_mq");

        builder.addColumn("_key", REFieldType.String, true);
        builder.addColumn("_spec", REFieldType.Int, true);
        builder.addColumn("_ch", REFieldType.Boolean, true);
        builder.addColumn("wx_au", REFieldType.Strings, true);
        builder.addColumn("cont", REFieldType.String, true);

        //session
        RESendSession session = (RESendSession) builder.build();
        session.start();
        for (int r = 0; r < 1; ++r) {
            session.setDocSchemaName("doc_schema_name_" + r);
            HashMap<String, String> user_desc = new HashMap<>();
            session.setUserDesc(user_desc);
            for (int i = 0; i < 10; ++i) {
                session.setString("_key", "value" + r);
                session.setInt("_spec", i);
                session.setBoolean("_ch", i % 2 == 0);
                String[] strs = {"str1",};
                session.setStrings("wx_au", strs);
                session.setString("cont", "色情");
                session.add();
            }
            session.flush();
        }

//		session.setDocSchemaName("doc_schema_name_all");
//		HashMap<String, String> user_desc = new HashMap<>();
//		user_desc.put("user", "test");
//		user_desc.put("pwd", "pwd");
//		user_desc.put("round", "all");
//		for (int r = 0; r < 3; ++r) {
//			session.setUserDesc(user_desc);
//			for (int i = 0; i < 10; ++i) {
//				session.setString("test1", "value" + r);
//				session.setInt("test2", i);
//				session.setBoolean("test3", i % 2 == 0);
//				String[] strs = {"str1", "Str2", "sTR3"};
//				session.setStrings("test4", strs);
//				session.add();
//			}
//			session.flush();
//		}
        session.shutdown();
    }
}
